package com.tt.fashionWebSite.controller;

import com.tt.fashionWebSite.dto.*;
import com.tt.fashionWebSite.service.Ad_ProductListProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.util.List;
import java.util.Map;


@Controller
public class Ad_ProductListProductController {
    @Autowired
    private Ad_ProductListProductService ad_productListProductService;

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/adProductListProduct", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminProductListProduct(HttpServletRequest request, @RequestBody LoaiDanhMucSanPhamDto productListProductDto) {
        return new JsonResponseDto<Integer>(ad_productListProductService.adminProductListProduct(productListProductDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/header/adProductListProductDelete", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<Integer> adminProductListProductDelete(HttpServletRequest request, @RequestBody List<LoaiDanhMucSanPhamDto> productListProductDto) {
        return new JsonResponseDto<Integer>(ad_productListProductService.adminProductListProductDelete(productListProductDto));
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllProductList", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<LoaiDanhMucSanPhamDto>> getAllProductList(HttpServletRequest request) {
        return new JsonResponseDto<List<LoaiDanhMucSanPhamDto>>(ad_productListProductService.getAllProductList(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/getAllProductCategory", method = RequestMethod.GET)
    public @ResponseBody
    JsonResponseDto<List<LoaiDanhMucDto>> getAllProductCategory(HttpServletRequest request) {
        return new JsonResponseDto<List<LoaiDanhMucDto>>(ad_productListProductService.getAllProductCategory(), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/toProductListProductPage/{maLoaiDMSP}", method = RequestMethod.GET)
    public @ResponseBody
    ModelAndView toPageListProduct(HttpServletRequest request, @PathVariable String maLoaiDMSP, Map<String, Object> map) throws ParseException {
        map.put("maLoaiDMSP", maLoaiDMSP);
        return new ModelAndView("admin/ad-product-listproduct-edit");
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/editListProduct", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<LoaiDanhMucSanPhamDto> getListProductInfoEdit(HttpServletRequest request, @RequestBody LoaiDanhMucSanPhamDto productListDto) {
        return new JsonResponseDto<LoaiDanhMucSanPhamDto>(ad_productListProductService.getListProductInfoEdit(productListDto), JsonResponseCode.SUCCESS);
    }

    @SuppressWarnings("rawtypes")
    @RequestMapping(value = "/admin/registerProductListEdit", method = RequestMethod.POST)
    public @ResponseBody
    JsonResponseDto<LoaiDanhMucSanPhamDto> registerProductListEdit(HttpServletRequest request, @RequestBody LoaiDanhMucSanPhamDto productListDto) {
        return new JsonResponseDto<LoaiDanhMucSanPhamDto>(ad_productListProductService.registerProductListEdit(productListDto), JsonResponseCode.SUCCESS);
    }
}
